<template>
  <div class="spotlight-page pages">
    <Top></Top>
    <!--    <Nav></Nav>-->
    <div class="content-nav">
      <div class="center-content" v-loading="tabLoading">
        <div class="nav">
          <div class="tab-item">
            <router-link to="/" exact>
              首页
            </router-link>
          </div>
          <router-link :to=" {path:'/spotlight/spotlightList',query:{id:tabActive}}" class="tab-item" v-for="(item,index) in tabList" :key="item.id">
            <div  class="tab-item">{{ item.name }}</div>
          </router-link>
        </div>
      </div>
    </div>

    <div class="info-list" v-if="noticeList.length>0">
      <div class="content-list" v-loading="positionLoading">
        <div class="bottom">
          <div class="text-item" v-for="item in noticeList" :key="item.id">
            <div class="title-item">
              <div class="title">{{ item.content }}</div>
              <div class="time">{{ item.create_time }}</div>
            </div>
            <div class="reply-item" v-if="item.reply_content">
                <div class="title">{{ item.reply_content }}</div>
                <div class="time">{{ item.reply_time_text }}</div>
            </div>
          </div>
        </div>
        <el-empty v-if="noticeList.length<=0" style="display: flex;justify-content: center;align-items: center;"></el-empty>
        <div class="string" v-if="noticeList.length>0 && count>limit"></div>
        <div  v-if="noticeList.length>0 && count>limit"  class="paging">
          <el-pagination
              background
              :page-size="limit"
              layout="prev, pager, next"
              prev-text="上一页"
              next-text="下一页"
              :total="count"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="this.page">
          </el-pagination>
          <div style="width: 110px;height: 1px"></div>
        </div>
      </div>
    </div>
    <div class="message-block">
      <div class="name">我要留言</div>
      <el-input placeholder="请输入您的留言..." type="textarea" rows="4" class="message-crl"  maxlength="300" show-word-limit clearable="true" v-model="form.content"></el-input>
      <div class="btn" @click="release">提交</div>
    </div>
  </div>
</template>

<script>
import Top from '@/components/Top.vue'
import Nav from '@/components/Nav.vue'
import Bottom from '@/components/Bottom.vue'
import BackHome from '@/components/BackHome.vue'
import {getCategoryApi} from "@/api/spotlight";
import {getListApi, releaseApi} from "@/api/mailbox";
import {validate} from "@/utils/validate";
export default {
  name: "spotlight",
  data(){
    return{
      tabActive: 3,
      limit: 45,
      page: 1,
      count: 0,
      tabList:[],
      tabLoading:false,
      positionLoading:false,
      noticeList:[],
     form:{
       content:''
     },
      rule:{
        content:{
          name:'留言内容',
          required:true,
        }}
    }
  },
  methods:{
    changeActive(e){
      this.menuActive=e
      this.getList()
    },
    getCategory() {
      this.tabLoading = true
      getCategoryApi({name:'新闻分类',is_main:1}).then((res) => {
        this.tabList = res.result;
      }).finally(()=>{
        this.tabLoading = false
      })
    },
    getList() {
      this.positionLoading = true
      getListApi({page:this.page,limit:this.limit}).then((res) => {
        this.noticeList = res.result.list;
        this.count = res.result.count
      }).finally(() => {
        this.positionLoading = false
      })
    },
    release() {
      if(validate(this.form,this.rule)){
      releaseApi(this.form).then((res) => {
        this.$message.success('提交成功');
        this.form.content=''
        this.getList()
      })}
    },
    handleSizeChange(e) {
      this.limit = e
      this.getList()
    },
    // 当前页change
    handleCurrentChange(e) {
      this.page = e
      sessionStorage.setItem('currentPage1',this.page)
      this.getList()
    },
  },
  components:{
    Top,
    Nav,
    Bottom,
    BackHome
  },
  mounted() {
    this.utils.createParams(this,this.$route.query);
    this.getCategory()
    this.getList()
  }
}
</script>

<style scoped lang="scss">
.content-list{
  width: 100%;
  padding: 25px;
  border: 1px solid #a9a4a4;
  ::v-deep{
    .el-pagination.is-background .el-pager li:not(.disabled).active{
      background-color: #CD1738;
    }
  }
  .top{
    display: flex;
    box-sizing: border-box;
    img{
      //width: 360px;
      height: 220px;
    }
    .text{
      padding: 0 30px;
      .title{
        font-weight: 900;
      }
      .small-title{
        color: #8f8a8a;
        margin-top: 25px;
      }
    }
  }
  .bottom{
    width: 100%;
    .text-item{
      overflow: hidden;
      cursor: pointer;
      border-bottom: 1px solid #F5F5F5;
      margin-top: 20px;
      padding-bottom: 15px;
      .title-item{
        .title{
          font-size: 15px;
          line-height: 30px;
        }
        .time{
          margin-top: 10px;
          font-size: 12px;
          margin-bottom: 15px;
          color: #767676;
        }
      }
      .reply-item{
         background: #F5F5F5;
         width:100% ;
         padding: 10px;
         font-size: 14px;
         border-radius: 6px;
         margin-bottom: 20px;
         .title{
           font-size: 15px;
           line-height: 30px;
         }
         .time{
           margin-top: 10px;
           font-size: 12px;
           margin-bottom: 10px;
           color: #767676;
         }
      }
    }
    .text-item:last-child{
      border-bottom: none;
    }
  }
  .string{
    width: 100%;
    height: 1px;
    background-color: #8f8a8a;
    margin: 20px 0;
  }
}
.content-nav{
  width: 100%;
  height: 50px;
  background: linear-gradient(to right, #FF5C61 30%, #FF5C61 60%, #FF5B5C 90%);
  a{
    text-decoration: none;
    color: #FFF;
  }
  .router-link-active {
    text-decoration: none;
    color: #FBBDBF;

  }

  .center-content{
    width: 1220px;
    height: 50px;
    margin: 0 auto;
    display: flex;
    .nav{
      width: calc((100% - 20px));
      height: 100%;
      display:flex;
      .tab-item{
        width: 98px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        color: #FFF;
        cursor: pointer;
        z-index:999
      }
      .tab-item.active{
        color: #FBBDBF;
        z-index:999
      }
      a{
        text-decoration: none;
        color: #FFF;
      }
      .router-link-active {
        text-decoration: none;
        color: #FBBDBF;
      }
    }
  }
}
.spotlight-page{
  position: relative;
  min-height:100vh;
  padding: 20px;
  a{
    text-decoration: none;
    color: #000000;
  }
  /*设置点击后的样式 */
  .router-link-active {
    text-decoration: none;
  }
  .info-list{
    width: 1100px;
    margin: 50px auto 0;
    display: flex;
    .back-home{
      position: fixed;
      right: 0;
    }
  }
  .message-block{
    width: 1100px;
    margin: 50px auto 0;
    padding: 20px;
    border: 1px solid #a9a4a4;
    .name{
      margin-bottom: 20px;
      font-size: 17px;
      font-weight: bold;
    }
    .message-crl{
      width: 100%;
    }
    .btn{
      margin-top: 30px;
      background: #F06CBC;
      color: #FFFFFF;
      width: 100px;
      height: 35px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 10px;
    }
  }
}
</style>
